package com.five.calendar.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;

import com.five.calendar.R;

/**
 * Created by xin on 2017/9/3.
 */

public class ImportaceChooseLayout extends RelativeLayout implements View.OnClickListener {
    RelativeLayout mImportance1;
    RelativeLayout mImportance2;
    RelativeLayout mImportance3;
    RelativeLayout mImportance4;
    private CallBack mCallBack;
    public ImportaceChooseLayout(Context context) {
        super(context);
    }

    public ImportaceChooseLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ImportaceChooseLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setCallBack(CallBack callBack){
        this.mCallBack = callBack;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mImportance1 = (RelativeLayout) findViewById(R.id.importance_1);
        mImportance2 = (RelativeLayout) findViewById(R.id.importance_2);
        mImportance3 = (RelativeLayout) findViewById(R.id.importance_3);
        mImportance4 = (RelativeLayout) findViewById(R.id.importance_4);
        mImportance1.setOnClickListener(this);
        mImportance2.setOnClickListener(this);
        mImportance3.setOnClickListener(this);
        mImportance4.setOnClickListener(this);
        setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                setVisibility(GONE);
                return true;
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.importance_1:
                mCallBack.callBack(0);
                setVisibility(GONE);
                break;
            case R.id.importance_2:
                mCallBack.callBack(1);
                setVisibility(GONE);
                break;
            case R.id.importance_3:
                mCallBack.callBack(2);
                setVisibility(GONE);
                break;
            case R.id.importance_4:
                mCallBack.callBack(3);
                setVisibility(GONE);
                break;
        }
    }

    public interface CallBack{
        void callBack(int importance);
    }
}
